class SRStatList extends GUIVertList;

// Display
var	texture	InfoBackground;

// State
var array<string>			ProgressName;
var	array<int>					StatProgress;
var	array<byte>					DisplayFormat; // 0 - value, 1 - time

function bool PreDraw(Canvas Canvas)
{
	return false;
}

function ClearList()
{
	while ( ProgressName.Length > 0 )
	{
		ProgressName.Remove(0,1);
	}
	while ( StatProgress.Length > 0 )
	{
		StatProgress.Remove(0,1);
	}
	while ( DisplayFormat.Length > 0 )
	{
		DisplayFormat.Remove(0,1);
	}
}

function AddRecord(int Value, string Description, byte Format)
{
	StatProgress.Insert(StatProgress.Length,1);
	StatProgress[StatProgress.Length-1] = Value;
	ProgressName.Insert(ProgressName.Length,1);
	ProgressName[ProgressName.Length-1] = Description;
	DisplayFormat.Insert(DisplayFormat.Length,1);
	DisplayFormat[DisplayFormat.Length-1] = Format;
}

function InitList( ClientPerkRepLink L )
{
	// Update the ItemCount and select the first item
	SetIndex(0);
	
	ClearList();

	AddRecord(L.RKillsStat,"Total kills",0);
	AddRecord(L.RHeadshotKillsStat,"Headshot damage",0);
	AddRecord(L.RMeleeDamageStat,"Melee damage",0);
	AddRecord(L.RShotgunDamageStat,"Shotgun damage",0);
	AddRecord(L.RWeldingPointsStat,"Welding points",0);
	AddRecord(L.RBullpupDamageStat,"Assault rifles damage",0);
	AddRecord(L.RStalkerKillsStat,"Stalker kills",0);
	AddRecord(L.RFlameThrowerDamageStat,"Fire damage",0);
	AddRecord(L.RSilentDamageStat,"Silencer guns and cold steel damage",0);
	AddRecord(L.RGunfighterDamageStat,"Pistols and Rifles damage",0);
	AddRecord(L.RExplosivesDamageStat,"Explosives damage",0);
	AddRecord(L.RFeedingKillsStat,"Submachine guns damage",0);
	AddRecord(L.RStalkersKilledWithExplosivesStat,"Machineguns damage",0);
	AddRecord(L.RDamageHealedStat,"Healed health",0);
	
	AddRecord(L.RSelfHealsStat,"Self heal",0);
	AddRecord(L.RCashDonatedStat,"Donated cash",0);
	
	AddRecord(L.RTotalZedTimeStat,"Total ZED-time",1);
	AddRecord(L.TotalPlayTime,"Total play-time",1);
	
	AddRecord(L.RSoleSurvivorWavesStat,"Sole survivor waves",0);
	AddRecord(L.RPatriarchKillsStat,"Patriarch kills",0);
	AddRecord(L.WinsCount,"Wins",0);
	AddRecord(L.LostsCount,"Losts",0);
	ItemCount = ProgressName.Length;

	if ( bNotify )
 	{
		CheckLinkedObjects(Self);
	}

	if ( MyScrollBar != none )
	{
		MyScrollBar.AlignThumb();
	}
}

final function string GetTimeText( int V )
{
	local int Hours, Minutes;

	Minutes = V / 60;
	Hours   = Minutes / 60;
	V -= (Minutes * 60);
	Minutes -= (Hours * 60);

	return Eval(Hours<10,"0"$Hours,string(Hours))$":"$Eval(Minutes<10,"0"$Minutes,string(Minutes))$":"$Eval(V<10,"0"$V,string(V));
}
function DrawStat(Canvas Canvas, int CurIndex, float X, float Y, float Width, float Height, bool bSelected, bool bPending)
{
	local float TempX, TempY;
	local float TempWidth, TempHeight;
	local string S;

	// Offset for the Background
	TempX = X;
	TempY = Y;

	// Initialize the Canvas
	Canvas.Style = 1;
	Canvas.Font = class'ROHUD'.Static.GetSmallMenuFont(Canvas);
	Canvas.SetDrawColor(255, 255, 255, 255);

	// Draw Item Background
	Canvas.SetPos(TempX, TempY);
	Canvas.DrawTileStretched(InfoBackground, Width, Height);

	// Select Text Color
	Canvas.SetDrawColor(0, 0, 0, 255);

	// Draw the Perk's Level Name
	Canvas.TextSize(ProgressName[CurIndex],TempWidth,TempHeight);
	TempX += Width*0.1f;
	TempY += (Height-TempHeight)*0.5f;
	Canvas.SetPos(TempX, TempY);
	Canvas.DrawText(ProgressName[CurIndex]$":");

	// Draw the Perk's Level
	switch( DisplayFormat[CurIndex] )
	{
	case 0:
		S = string(StatProgress[CurIndex]);
		break;
	case 1:
		S = GetTimeText(StatProgress[CurIndex]);
		break;
	}
	Canvas.TextSize(S,TempWidth,TempHeight);
	Canvas.SetPos(X + Width*0.88f - TempWidth, TempY);
	Canvas.DrawText(S);
}

function float PerkHeight(Canvas c)
{
	return (MenuOwner.ActualHeight() / 14.0) - 1.0;
}

defaultproperties
{
	OnDrawItem=DrawStat
	OnPreDraw=PreDraw

	InfoBackground=Texture'KF_InterfaceArt_tex.Menu.Item_box_bar'

	FontScale=FNS_Medium
	GetItemHeight=PerkHeight

	ItemCount=27
	ProgressName(0)="Healed damage"
	ProgressName(1)="Welded hitpoints"
	ProgressName(2)="Shotgun damage"
	ProgressName(3)="Headshot damage"
	ProgressName(4)="Chainsaw kills"
	ProgressName(5)="Stalker kills"
	ProgressName(6)="Assault rifles damage"
	ProgressName(7)="Melee damage"
	ProgressName(8)="Flame thrower damage"
	ProgressName(9)="Self healed count"
	ProgressName(10)="Sole survivor waves count"
	ProgressName(11)="Cash donated"
	ProgressName(12)="Submachine guns damage"
	ProgressName(13)="Hunting shotgun kills"
	ProgressName(14)="Sharpshooter statistics modified"
	ProgressName(15)="Gibbed fleshpounds"
	ProgressName(16)="Machineguns damage"
	ProgressName(17)="Explosives damage count"
	ProgressName(18)="Gibbed zombies count"
	ProgressName(19)="Bloat kills"
	ProgressName(20)="Total ZED-time"
	ProgressName(21)="Siren kills"
	ProgressName(22)="Total kills"
	ProgressName(23)="Knife kills as medic"
	ProgressName(24)="Total playtime"
	ProgressName(25)="Won games"
	ProgressName(26)="Lost games"
	ProgressName(27)="Silencer weapons and cold steel damage"

	StatProgress(26)=0
	DisplayFormat(20)=1
	DisplayFormat(24)=1
	DisplayFormat(26)=0
}